package com.institute.entity;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.institute.entity.dto.InstituteDTO;
import com.institute.entity.dto.PositionDTO;
import com.staff.entity.Staff;


@Entity
@Table(name="t_institute")
public class Institute {//部门实体类
	private Long id;
	private String code;
	private String name;
	private Integer capacity;
	private String description;
	private Institute father;//父节点
	private Staff principal;//负责人
	private Integer level;
	
	
	public Institute() {
		super();
	}
	public Institute(InstituteDTO dto,Institute father) {
		super();
		this.id = dto.getDeptId();
		this.code = dto.getCode();
		this.name = dto.getName();
		this.capacity = dto.getCapacity();
		this.father = father;
		if(father == null) {
			this.level = 1;
		}else {
			this.level = father.getLevel()+1;
		}
	}
	
	public Institute(PositionDTO p) {
		super();
		this.id = p.getId();
		this.code = p.getCode();
		this.name = p.getName();
		this.capacity = p.getCapacity();
		this.description = p.getDescription();
	}
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	public Long getId() {
		return id;
	}
	@JsonIgnore
	@ManyToOne(cascade=CascadeType.ALL)
	public Institute getFather() {
		return father;
	}
	@JsonIgnore
	@ManyToOne(cascade=CascadeType.ALL)
	public Staff getPrincipal() {
		return principal;
	}
	public String getCode() {
		return code;
	}
	public String getName() {
		return name;
	}
	public Integer getCapacity() {
		return capacity;
	}
	public String getDescription() {
		return description;
	}
	public void setId(Long id) {
		this.id = id;
	}
	public void setCode(String code) {
		this.code = code;
	}
	public void setName(String name) {
		this.name = name;
	}
	public void setCapacity(Integer capacity) {
		this.capacity = capacity;
	}
	public void setDescription(String description) {
		this.description = description;
	}

	public void setFather(Institute father) {
		this.father = father;
	}
	public void setPrincipal(Staff principal) {
		this.principal = principal;
	}
	public Integer getLevel() {
		return level;
	}
	public void setLevel(Integer level) {
		this.level = level;
	}
	
	
}
